package org.dromara.system.service.impl;

import org.dromara.system.service.SysDictDataService;
import org.dromara.system.pojo.entity.SysDictDataDO;
import org.dromara.system.pojo.bo.SysDictDataBO;
import org.dromara.system.pojo.qo.SysDictDataQO;
import org.dromara.system.pojo.vo.SysDictDataVO;
import org.dromara.system.mapper.SysDictDataMapper;
import org.springframework.stereotype.Service;

import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.utils.BeanCopyUtils;

import java.util.List;

/**
 * 字典数据表 服务层实现。
 *
  * @author mkj
  * @since 2024-07-21
 */
@RequiredArgsConstructor
@Service
public class SysDictDataServiceImpl  implements SysDictDataService {

    private final SysDictDataMapper sysDictDataMapper;

    @Override
    public boolean add(SysDictDataBO sysDictDataBO) {
        SysDictDataDO sysDictDataDO = BeanCopyUtils.copy(sysDictDataBO, SysDictDataDO.class);
        return sysDictDataMapper.insert(sysDictDataDO) > 0;
    }

    @Override
    public boolean remove(Long id) {
        return sysDictDataMapper.deleteById(id) > 0;
    }

    @Override
    public boolean update(SysDictDataBO sysDictDataBO) {
        SysDictDataDO sysDictDataDO = BeanCopyUtils.copy(sysDictDataBO, SysDictDataDO.class);
        return sysDictDataMapper.update(sysDictDataDO) > 0;
    }

    @Override
    public List<SysDictDataVO> list(SysDictDataQO sysDictDataQO) {
        SysDictDataDO sysDictDataDO = BeanCopyUtils.copy(sysDictDataQO, SysDictDataDO.class);
        QueryWrapper queryWrapper = QueryWrapper.create(sysDictDataDO);
        return sysDictDataMapper.selectListByQueryAs(queryWrapper, SysDictDataVO.class);
    }

    @Override
    public SysDictDataVO getInfo(@PathVariable Long id) {
        SysDictDataDO sysDictDataDO = sysDictDataMapper.selectOneById(id);
        if (sysDictDataDO == null){
            return null;
        }
        return BeanCopyUtils.copy(sysDictDataDO, SysDictDataVO.class);
    }

    @Override
    public Page<SysDictDataVO> page(SysDictDataQO page) {
        return sysDictDataMapper.paginateAs(page.getPageNumber(), page.getPageSize(), QueryWrapper.create(page), SysDictDataVO.class);
    }

}

